<?php

function isDateAfter($pivotDate, $testDate){

	$pivot = new DateTime($pivotDate);
	$test = new DateTime($testDate);
	
	$pivotYear = $pivot->format('Y');
	$pivotMonth = $pivot->format('m');
	$pivotDay = $pivot->format('d');
	
	$testYear = $test->format('Y');
	$testMonth = $test->format('m');
	$testDay = $test->format('d');

	if($testYear < $pivotYear){
		return false;
	}elseif(($testMonth < $pivotMonth) && ($testYear == $pivotYear)){
		return false;
	}elseif(($testDay <= $pivotDay) && ($testMonth == $pivotMonth) && ($testYear == $pivotYear)){
		return false;
	}else{
		return true;
	}
}

function getMonthName($mth){
	$testDate = new DateTime();
	$testDate->setDate(2007, $mth, 1);
	return $testDate->format('M');
}

function getNumericMth($mth){
	if($mth == "Jan"){
		return 1;
	}elseif($mth == "Feb"){
		return 2;
	}elseif($mth == "Mar"){
		return 3;
	}elseif($mth == "Apr"){
		return 4;
	}elseif($mth == "May"){
		return 5;
	}elseif($mth == "Jun"){
		return 6;
	}elseif($mth == "Jul"){
		return 7;
	}elseif($mth == "Aug"){
		return 8;
	}elseif($mth == "Sep"){
		return 9;
	}elseif($mth == "Oct"){
		return 10;
	}elseif($mth == "Nov"){
		return 11;
	}elseif($mth == "Dec"){
		return 12;
	}
}

function getLastDayOfMth($mth, $year){
	$curMth = $mth;
	$curYear = $year;
	$curDay = 28;
	
	if(strlen($curMth) == 3){
		$curMth = getNumericMth($mth);
	}
	
	$testDate = new DateTime();
	$testDate->setDate($curYear, $curMth, $curDay);
	
	while($curDay <= 31){
		if(checkdate($curMth, $curDay, $curYear) == true){
			$testDate->setDate($curYear, $curMth, $curDay);
		}
		$curDay ++;
	}
	
	return $testDate->format('Y-m-d');
}

function getFirstDayOfCurMth(){
	
	$curMth = date('m');
	$curYear = date('Y');
	
	$testDate = new DateTime();
	$testDate->setDate($curYear, $curMth, 1);
	
	return $testDate->format('Y-m-d');
	
}

function getLastDayOfCurMth(){

	$curMth = date('m');
	$curYear = date('Y');
	$curDay = 28;
	
	$testDate = new DateTime();
	$testDate->setDate($curYear, $curMth, $curDay);
	
	while($curDay <= 31){
		if(checkdate($curMth, $curDay, $curYear) == true){
			$testDate->setDate($curYear, $curMth, $curDay);
		}
		$curDay ++;
	}
	
	return $testDate->format('Y-m-d');

}

function getLastDay($mth, $year){
	$curMth = $mth;
	$curYear = $year;
	$curDay = 28;
	
	if(strlen($curMth) == 3){
		$curMth = getNumericMth($mth);
	}
	
	$testDate = new DateTime();
	$testDate->setDate($curYear, $curMth, $curDay);
	
	while($curDay <= 31){
		if(checkdate($curMth, $curDay, $curYear) == true){
			$testDate->setDate($curYear, $curMth, $curDay);
		}
		$curDay ++;
	}
	
	return $testDate->format('d');
}

?>